<?php
namespace app\service;
use app\bean\GraphArticleBean;
use app\cls\tom\Config;
use app\cls\tom\Encrypt;
use app\cls\tom\Ks3OS;
use app\cls\tom\Praise;
use app\cls\tom\SysResource;
use app\cls\tom\Response;
use app\cls\tom\Tools;
use app\lib\db\DbException;

/**
 * Created by PhpStorm.
 * User: tom_xia
 * Date: 2018/5/14
 * Time: 16:30
 * 直播管理（图文管理/评论管理）
 */
class Home_page{

    /**
     * 主页展示接口
     */
    public function lists($page,$limit){
        $db = SysResource::getDB(false);
        $db->select("id,material_id,video_url,pic,video_name,time_length,join_time,dub_number");
        $db->from("video");
        $db->where(["status"=>1,"type"=>2]);
        $total = $db->count_all_results();
        $db->limit($limit,($page-1)*$limit);
        $query = $db->get();
        $result = $query->all();
        return new Response(0,"ok",$result,$total);
    }

    /**
     * 用户提交状态查看接口
     */
    public function view_status($user_code){
        $db = SysResource::getDB(false);
        $db->select("user_material_uuid,id,pic,video_name,status,add_time");
        $db->from("user_material");
        $db->where(["user_uuid"=>$user_code,"is_save"=>1]);
        $total = $db->count_all_results();
        $db->order_by(["add_time"=>"desc"]);
        $query = $db->get();
        $result = $query->all();
        return new Response(0,"ok",$result,$total);
    }

    /**
     * 视频详情页接口
     */
    public function video_detail($ori_material_uuid,$user_uuid,$id){
        $db = SysResource::getDB(false);
        $db->select("music_video_url,head_image,nickname,add_time,zan,custom_zan,ori_material_uuid,click_yh,click_666,click_football,click_jion");
        $db->from("user_material");
        $db->where(["ori_material_uuid"=>$ori_material_uuid,"user_uuid"=>$user_uuid,"id"=>$id,"status"=>"1"]);
        $total = $db->count_all_results();
        $query = $db->get();
        $result = $query->all();
        return new Response(0,"ok",$result,$total);
    }

    /**
     * 开始配音界面
     */
    public function start_dub($material_id){
        $db = SysResource::getDB(false);
        $db->select("id,material_id,video_url,video_urls,pic,video_name,time_length,`lines`");
        $db->from("video");
        $db->where(["material_id"=>$material_id,"type"=>2]);
        $total = $db->count_all_results();
        $query = $db->get();
        $result = $query->all();
        return new Response(0,"ok",$result,$total);
    }

    /**
     * 查询音效
     */
    public function music($id){
        $db = SysResource::getDB(false);
        $db->select("music_id,material_id,mix_url");
        $db->from("video_music");
        $db->where(["material_id"=>$id]);
        $total = $db->count_all_results();
        $query = $db->get();
        $result = $query->all();
        return new Response(0,"ok",$result,$total);
//        return $result;
    }

    public function musics($id){
        $db = SysResource::getDB(false);
        $db->select("id,pic,time_length,music_name,music_url");
        $db->from("music");
        $db->where(["id"=>$id]);
        $total = $db->count_all_results();
        $query = $db->get();
        $result = $query->all();
        return new Response(0,"ok",$result,$total);
//        return $result;
    }
}